<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" ><!--引入shiro和thymeleaf的依赖-->
<head>
    <meta charset="utf-8">
    <title>员工</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <script th:src="@{/layui/layui.all.js}" charset="utf-8"></script><!--要用模板引擎映入-->
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">ID</label>
                    <div class="layui-input-block">
                        <input type="text" name="empid" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">员工名</label>
                    <div class="layui-input-block">
                        <input type="text" name="empname" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">手机</label>
                    <div class="layui-input-block">
                        <input type="text" name="phone" placeholder="请输入手机" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <select name="sex">
                            <option>不限</option>
                            <option value="1">男</option>
                            <option value="2">女</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search"
                            id="serchbtn">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">

                <button class="layui-btn layuiadmin-btn-useradmin" id="addjob" data-type="add">添加</button>
                <button class="layui-btn layuiadmin-btn-useradmin" id="export" data-type="export">导出</button>

            </div>

            <table class="layui-hide" id="test" lay-filter="test"></table>
            <!--绑定swich开关-->

            <!--     加入lay-event="switch"，改为toolbar,事件是switch-->
            <script type="text/html" id="status">
                {{#  if(d.status==0){ }}
                <a lay-event="switch">

                    <input type="checkbox" name="status"  lay-skin="switch" lay-event="switch" checked lay-text="启用|禁用"
                           value={{ d.status }}
                           lay-filter="status">
                </a>
                {{#  } else if(d.status==1) { }}
                <a lay-event="switch">
                    <input type="checkbox" name="status"  lay-skin="switch" lay-text="启用|禁用" value={{ d.status}}
                           lay-filter="status">
                </a>
                {{#  } }}
            </script>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
                    <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
                    <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
                </div>
            </script>

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                <a class="layui-btn layui-btn-xs" lay-event="pauseJob">暂停</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="resumeJob">恢复任务</a>
            </script>


            <script type="text/html" id="imgTpl">
                <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.avatar }}>
            </script>
            <script type="text/html" id="table-useradmin-webuser">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                        class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                        class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script th:src="@{/layuiadmin/layui/layui.all.js}"></script>
<script src="/js/jquery-1.7.2.min.js"></script>

<script>
    //获取token
    layui.use(['table', 'form'], function () {
        var table = layui.table, form = layui.form;

        var tableData;
        table.render({


            elem: '#test'
            , url: '/list'//要是json 格式
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-tips'
            }]
            , title: '任务表 '
            , cols: [
                [
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'jobId', title: 'ID', width: 80, fixed: 'left', unresize: true, sort: true}
                    , {field: 'jobName', title: '任务名', width: 200, edit: 'text'}

                    // , {field: 'pic', title: '图片', templet: function (data) {
                    //           console.log(data);
                    //
                    //           return '<div ><img src=' + data.pic + '></div>' /*用template语法*/
                    //         }
                    //       }
                    , {field: 'jobGroup', title: '任务组名', width: 200}//field 全部小写
                    , {field: 'invokeTarget', title: '调用目标字符串', width: 80}
                    , {field: 'cronExpression', title: '执行表达式', width: 80}
                    , {field: 'misfirePolicy', title: '计划策略', width: 80}
                    , {field: 'concurrent', title: '并发执行', width: 120}
                    , {field: 'status', title: '任务状态', width: 120}
                    , {field: 'concurrent', title: '并发执行', width: 120}
                    , {field: 'status', title: '状态', width: 120, toolbar: "#status", filter: true}//这里绑定开关
                    , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
                ]
            ]/*要把大括号分开，不然识别不了*/
            , page: true


        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            }
            ;
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            console.log(data);
            var jobId = data.jobId;
            var status =data.status;
            console.log("当前的id" + jobId);
            //console.log(obj)
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    //再将数据库的也删除
                    $.ajax({
                        method: "post",
                        data: {
                            jobId: jobId
                        },
                        url: '/delete'//发送id
                        , success: function (data) {
                            console.log(data.msg)
                            layer.msg(data.msg);

                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer.prompt({
                    formType: 2
                    , value: data.email
                }, function (value, index) {
                    obj.update({
                        email: value
                    });
                    layer.close(index);
                });
            } else if (obj.event == 'switch') {//改变状态
                console.log("当前的用户id" + jobId);
                console.log("当前的状态" + status);
                layer.confirm("确定启用吗？",{
                    btn: ['确定','取消'] //按钮
                },function(){
                    $.ajax({
                        type: 'post',
                        url: '/updstatus',
                        data: {jobId: jobId, status: status},

                        error: function (data) {
                            console.log(data);
                            layer.msg('数据异常，操作失败！');
                        },
                        success: function (data) {
                            console.log(data);
                            layer.msg('更改成功', {icon: 1});
                            table.reload('test');
                            layer.close()
                        },

                        dataType: 'JSON'
                    });
                },function () {
                    table.reload('test');
                    layer.close();
                });



            }
        });
    });
</script>

<script>
    layui.use(['index', 'useradmin', 'table'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table;

        //监听搜索
        form.on('submit(LAY-user-front-search)', function (data) {
            var field = data.field;
            console.log(field)
            // table.reload('testReload', {
            //   url: 'https://www.easy-mock.com/mock/5c131015dada7b27ac3a5c36/titi/noData'
            //   // ,methods:"post"
            //   ,request: {
            //     pageName: 'page' //页码的参数名称，默认：page
            //     ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            //   }
            //   ,where: {
            //     query : inputVal
            //   }
            //   ,page: {
            //     curr: 1
            //   }
            //执行重载

            table.reload('test', {
                url: '/emp/search',//查询的地址
                where: field,
                page: {
                    curr: 1
                }
            });
        });
        $('#serchbtn').on('click', function () {
            console.log("active重载")
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
    //事件
    var active = {
        batchdel: function () {
            var checkStatus = table.checkStatus('LAY-user-manage')
                , checkData = checkStatus.data; //得到选中的数据

            if (checkData.length === 0) {
                return layer.msg('请选择数据');
            }

            layer.prompt({
                formType: 1
                , title: '敏感操作，请验证口令'
            }, function (value, index) {
                layer.close(index);

                layer.confirm('确定删除吗？', function (index) {

                    //执行 Ajax 后重载
                    /*
                    admin.req({
                      url: 'xxx'
                      //,……
                    });
                    */
                    table.reload('LAY-user-manage');
                    layer.msg('已删除');
                });
            });
        }
        , add: function () {
            layer.open({
                type: 2
                , title: '添加用户'
                , content: 'add.html'
                , maxmin: true
                , area: ['500px', '450px']
                , btn: ['确定', '取消']
                , yes: function (index, layero) {
                    var iframeWindow = window['layui-layer-iframe' + index]
                        , submitID = 'LAY-user-front-submit'
                        , submit = layero.find('iframe').contents().find('#' + submitID);

                    //监听提交
                    iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                        var field = data.field; //获取提交的字段

                        //提交 Ajax 成功后，静态更新表格中的数据
                        //$.ajax({});
                        table.reload('LAY-user-front-submit'); //数据刷新
                        layer.close(index); //关闭弹层
                    });

                    submit.trigger('click');
                }
            });
        }

    };
    $("#export").click(function () {
        console.log("点击导出")
        $.ajax({
            type:"post",
            url:"/export"
            ,success:function (data) {
                console.log(data);

            }
        })
    });
    $("#addjob").click(function () {
        layer.open({
            type: 2,//2代表content可以发生请求
            title: '用户授权',
            shade: 0.4,
            fixed: false,
            resize:false,
            anim: 5,
            area: ['500px', '550px'],
            content: '/toadd'//这里去跳转页面
            //iframe的url
        });

    })


</script>
</body>
</html>
